/**
 * Copyright (C) 2022-2023
 * All rights reserved, Designed By www.tonetn.com
 * 注意：
 * 本软件为www.tonetn.com开发研制，未经购买不得使用
 * 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
 * 一经发现盗用、分享等行为，将追究法律责任，后果自负
 */
package com.xunyin.modules.log.service.mapper;

import com.xunyin.common.mapper.CoreMapper;
import com.xunyin.modules.log.domain.TimelongRecord;
import com.xunyin.modules.membersuser.vo.MemberUserTimeLongVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author admin
 * @date 2022-10-22
 */
@Repository
public interface TimelongRecordMapper extends CoreMapper<TimelongRecord> {

    @Select("select str.id as id,str.main_id as mainId,str.source as source," +
            "case when str.source = 1 then '后台添加'" +
            "when str.source = 2 then '转让'" +
            "when str.source = 3 then '本人使用'" +
            "when str.source = 4 then '退款返还'" +
            "else '其他' end as sourceName," +
            "str.timelong  as timelong," +
            "str.giver as giver," +
            "smu1.member_user_phone as giverPhone," +
            "str.recipient as recipient," +
            "smu2.member_user_phone as recipientPhone," +
            "str.order_no  as orderNo," +
            "str.remark as remark" +
            " from t_timelong_record str " +
            " left join t_members_user smu1 on str.giver = smu1.id and smu1.status = 1" +
            " left join t_members_user smu2 on str.recipient = smu2.id and smu2.status = 1" +
            " where str.status = 1" +
            " and (str.giver = #{memberUserId} or str.recipient = #{memberUserId}) " +
            " order by str.create_time desc ")
    List<MemberUserTimeLongVo> getTimelongRecordByUserId(@Param("memberUserId") Integer memberUserId);

}
